# \--------------------------- Loli Pan-ic -----------------------------------/
# \--------------------- RNG Functions and Data ------------------------------/

import random

LOLI_PILE_QUEUE = []

class Loli_Pile:
    def __init__(self, ident, chance):
        self.baseChance, self.incChance = chance, chance
        self.ident = ident
        
    def checkProb(self):
        if bagOfTricks(int(self.incChance)) == True:
            return True
        else:
            self.incChance = self.incChance + self.baseChance if self.incChance < 100 else 100
            return False
            
def pileOfLolis(chance):
    ident = random.randint(1,99999999)
    new_pile = Loli_Pile(ident, chance)
    LOLI_PILE_QUEUE.append(new_pile)
    return ident

def checkPiles(ident):
    for pile in LOLI_PILE_QUEUE:
        pile_ind = LOLI_PILE_QUEUE.index(pile)
        if pile.ident == ident:
            rVal = pile.checkProb()
            if rVal == True:
                del LOLI_PILE_QUEUE[pile_ind]
                return True
            else:
                return False

def bagOfTricks(prob):
    bag = []
    while len(bag) < prob:
        trick = random.randint(1,100)
        if trick not in bag:
            bag.append(trick)
    draw = random.randint(1,100)
    if draw in bag:
        return True
    else:
        return False
    
# def leechList(loli_id, 
    
def basedBias(options, biasList):
    # Choose an option based on a random value within ranges of numbers 1-100
    opt_max = len(options)
    bag = []
    draw = random.randint(1, 100)
    total = 0
    
    for bias in biasList:
        min_val = total+1
        max_val = total + bias
        trick = range(min_val,max_val+1)
        bag.append(trick)
        total = max_val
    
    deck_num = 0
    for deck in bag:
        if draw in deck:
            return options[deck_num]
        else:
            deck_num += 1
    else:
        raise ValueError('Probability error in basedBias.')
    
def choose_event():
    choice = random.choice(events_primary)
    choice2 = random.choice(choice)
    return choice2
    
# ----------------------  RNG EVENT POOL --------------------------------------

island_locations = ['house',
                    'forest',
                    'mountain',
                    'beach']

# ------

event_gather_basic_woodmess = ['loliName gathered some wood.',
                               'loliName played around with some sticks and ended up bringing back more.',
                               ]

event_gather_basic_stonemess = ['loliName brought back a bunch of rocks.',
                                'loliName found some mildly interesting rocks and brought them with her.'
                                ]

event_gather_basic_flintmess = ['loliName: \'Look at this weird rock I found!\'',
                                'Is that a flint stone in loliName\'s pocket, or is she just happy to see you?'
                                ]

event_gather_basic_claymess = ['loliName dug up some clay.',
                                'loliName brought back a big glob of clay.'
                                ]

event_gather_basic = [('gathering',event_gather_basic_woodmess,'inc_wood',4),
                      ('gathering',event_gather_basic_stonemess,'inc_stone',4),
                      ('gathering',event_gather_basic_flintmess,'inc_flint',4),
                      ('gathering',event_gather_basic_claymess,'inc_clay',4)]

# ------

event_sleep_sleep = ['loliName slept peacefully.',
                     'loliName\'s sleeping face is quite adorable.']

event_sleep_nosleep = ['loliName couldn\'t sleep.',
                       'Try as she might, loliName was unable to sleep.']

event_sleep_middlewake = ['loliName was woken up in the middle of the night.',
                          'loliName\'s sleep was interrupted.']

event_sleep = [('sleeping',event_sleep_sleep,'none',8),
               ('cannot sleep',event_sleep_nosleep,'none',8),
               ('woken from sleep',event_sleep_middlewake,'none',8)]

# ------

event_craft = []

# ------

event_lazy_layaround = ['loliName felt like laying around instead.',
                        'You find loliName lounging around instead of working.']

event_lazy_nap = ['loliName went to go take a nap.',
                  'You catch loliName napping.']

event_lazy_laytree = ['You find loliName laying on a tree branch. How lazy of her.',
                      'loliName decided to pull a Lucchini and took a nap in a tree.']

event_lazy = [('laying around',event_lazy_layaround,'none',4),
              ('napping',event_lazy_nap,'none',4),
              ('laying in a tree',event_lazy_laytree,'none',4)]

# ------

event_play = []

# ------

event_cook = []

# ------

event_build = []

# ------

event_hunt = []

# ------

event_eat = []

# ------

event_drink = []

# ------

event_combat = []

# ------

events_primary = [event_gather_basic,
                  #'fall_asleep':event_sleep,
                  #'craft':event_craft,
                  event_lazy]
                  #'play':event_play,
                  #'cook':event_cook,
                  #'build':event_build,
                  #'hunt':event_hunt}
                  
events_needs = [event_eat,
                event_drink]

events_combat = [event_combat]

# ------------------------ RESOURCES ------------------------------------------

TYP_MAX = 9999
rsrc_list = [('wood',TYP_MAX),
             ('stone',TYP_MAX),
             ('flint',TYP_MAX),
             ('clay',TYP_MAX),
            ]